package chapter1.No1_7_停止线程.b判断线程是否是停止状态;

/**
 * *：interrupted() 测试当前线程是否已经中断。这个“当前线程”就是main
 *
 * @author liujian
 * @version 2016/11/8 0008
 */
public class T3_MyThreadIsInterrupted extends Thread {

    @Override
    public void run() {
        for(int i = 0; i < 50000; i++) {
            System.out.println(i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        T3_MyThreadIsInterrupted m1 = new T3_MyThreadIsInterrupted();
        m1.start();
        Thread.sleep(100);
        m1.interrupt();
        System.out.println("是否停止1？"+m1.isInterrupted());
        System.out.println("是否停止2？"+m1.isInterrupted());
        // 两个一起用，就能更加清楚的分析了
        System.out.println("是否停止3？"+Thread.interrupted());
        System.out.println("是否停止4？"+Thread.interrupted());
        // 这更能说明m1.interrupted() 等价于 Thread.interrupted()
        System.out.println("是否停止5？"+m1.interrupted());
        System.out.println("是否停止6？"+m1.interrupted());


    }
}
